package tetrisbattle;

import java.awt.Dimension;

public class TetriminoGrid extends TetrisBattleGrid{
    private void changeGrid(SHAPE shape) {
        if(shape == SHAPE.I){
            intToBrick.put(dimToInt.get(new Dimension(0, 4)), 1);
            intToBrick.put(dimToInt.get(new Dimension(1, 4)), 1);
            intToBrick.put(dimToInt.get(new Dimension(2, 4)), 1);
            intToBrick.put(dimToInt.get(new Dimension(3, 4)), 1);
        }else if(shape == SHAPE.J){
            intToBrick.put(dimToInt.get(new Dimension(3, 3)), 1);
            intToBrick.put(dimToInt.get(new Dimension(1, 4)), 1);
            intToBrick.put(dimToInt.get(new Dimension(2, 4)), 1);
            intToBrick.put(dimToInt.get(new Dimension(3, 4)), 1);
        }else if(shape == SHAPE.L){
            intToBrick.put(dimToInt.get(new Dimension(5, 3)), 1);
            intToBrick.put(dimToInt.get(new Dimension(1, 4)), 1);
            intToBrick.put(dimToInt.get(new Dimension(2, 4)), 1);
            intToBrick.put(dimToInt.get(new Dimension(3, 4)), 1);
        }else if(shape == SHAPE.T){
            intToBrick.put(dimToInt.get(new Dimension(3, 3)), 1);
            intToBrick.put(dimToInt.get(new Dimension(3, 5)), 1);
            intToBrick.put(dimToInt.get(new Dimension(2, 4)), 1);
            intToBrick.put(dimToInt.get(new Dimension(3, 4)), 1);
        }else if(shape == SHAPE.S){
            intToBrick.put(dimToInt.get(new Dimension(3, 3)), 1);
            intToBrick.put(dimToInt.get(new Dimension(2, 5)), 1);
            intToBrick.put(dimToInt.get(new Dimension(2, 4)), 1);
            intToBrick.put(dimToInt.get(new Dimension(3, 4)), 1);
        }else if(shape == SHAPE.Z){
            intToBrick.put(dimToInt.get(new Dimension(3, 6)), 1);
            intToBrick.put(dimToInt.get(new Dimension(2, 5)), 1);
            intToBrick.put(dimToInt.get(new Dimension(2, 4)), 1);
            intToBrick.put(dimToInt.get(new Dimension(3, 5)), 1);
        }else if(shape == SHAPE.O){
            intToBrick.put(dimToInt.get(new Dimension(3, 4)), 1);
            intToBrick.put(dimToInt.get(new Dimension(3, 5)), 1);
            intToBrick.put(dimToInt.get(new Dimension(2, 4)), 1);
            intToBrick.put(dimToInt.get(new Dimension(2, 5)), 1);
        }
        
        changeColor();
    }
    
    private enum SHAPE {I, J, L, T, S, Z, O};
    private SHAPE gridShape;
    private int randomShape;
    
    public TetriminoGrid(){
        super(4, 10);
        
        this.setVisible(false);
        this.setFocusable(false);
        this.setEnabled(true);
        
        assignShape();
    }
    
    public int[] getFirstColor(){
        int[] firstRow = new int[this.cols];
        for(int i = 0; i < this.cols; i++){
            int j = dimToInt.get(new Dimension(3, i));
            firstRow[i] = intToBrick.get(j);
        }
        System.out.println();
        return firstRow;
    }
    
    private void assignShape(){
        randomShape = (int) (((Math.random() * 123) + 32) % 7);
        switch (randomShape){
            case 0: gridShape = SHAPE.I; break;
            case 1: gridShape = SHAPE.J; break;
            case 2: gridShape = SHAPE.L; break;
            case 3: gridShape = SHAPE.T; break;
            case 4: gridShape = SHAPE.S; break;
            case 5: gridShape = SHAPE.Z; break;
            case 6: gridShape = SHAPE.O; break;
        }
        changeGrid(gridShape);
    }
}
